package com.rd.student.dashuju.sunwenzhuo.Test1.calculator;

import java.util.Scanner;

public class CalculatorTest {
    public static void main(String[] args) {
        num();
    }

    public static double num() {
        double i1 = 0;
        double i2 = 0;
        double n = 0.0;
        int i = 0;
        Scanner scanner = new Scanner(System.in);

        while (true) {
            if (i==0) {
                System.out.println("请输入第一个数");
                if (scanner.hasNextDouble()) {
                    i1 = scanner.nextDouble();
                }else {
                    System.out.println("输入有误");
                    return num();
                }

            } else {
                i1 = n;
            }
            i++;
            //+-*/
            System.out.println("请输入符号");
            String str = scanner.next();

            System.out.println("请输入第二个数");
            if (scanner.hasNextDouble()) {
                i2 = scanner.nextDouble();
            }else {
                System.out.println("输入有误");
                return num();
            }

            switch (str) {
                case "+":
                    n = i1 + i2;
                    System.out.println("结果是：" + n);
                    continue;
                case "-":
                    n = i1 - i2;
                    System.out.println("结果是：" + n);
                    continue;
                case "*":
                    n = i1 * i2;
                    System.out.println("结果是：" + n);
                    continue;
                case "/":
                    n = i1 / i2;
                    System.out.println("结果是：" + n);
                    continue;
            }
        }
    }
}
